Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow manual specification of python executable during build #1602

Merged
merged 5 commits into from
Jan 15, 2024
Merged

Allow manual specification of python executable during build #1602

merged 5 commits into from
Jan 15, 2024

Conversation

tguruswamy
Copy link
Contributor

common/configure and qt/configure now support --python=PYTHON_PATH option to manually specify the python executable. A full, absolute path is preferred but any valid path should work.

Previous --python and --python3 options also should still work, representing /usr/bin/python and /usr/bin/python3 respectively.

Tests pass on openSUSE Leap 15.5 and Tumbleweed.

This is the quick fix for #1574 .

@tguruswamy
Copy link
Contributor Author

I note that you can no longer change the python path twice by rerunning configure -- run it once only. But hopefully there isn't anyone relying on that.

@buhtz buhtz requested a review from aryoda January 8, 2024 14:19
@buhtz
Copy link
Member

buhtz commented Jan 8, 2024

Thanks a lot for this contribution.
I am not into makefiles to review this PR.
Maybe we can ask on bit-dev for assistance?

@aryoda
Copy link
Contributor

aryoda commented Jan 9, 2024

@buhtz I will reviewing and testing this in the next days

I note that you can no longer change the python path twice by rerunning configure -- run it once only.

Do you mean a 2nd ./configure does not change the Makefile's Python3? Strange, I will test this on Ubuntu...

Edit: OK, it is because sed does not find ^python3 anymore to replace it (once it has been changed).
This is IMHO a source of problems that are hard to find.
Perhaps there is a better solution that allows changing Python with every ./configure call.
@ALL Any proposals?

common/configure Outdated
esac
sed -e "s/^python3\? /python${PYVERSION} /g" \
-e "s/^ssh-agent python3\? /ssh-agent python${PYVERSION} /g" \
sed -e "s#^python3 #${PYTHON} #g" \
Copy link
Contributor

@aryoda aryoda Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is # instead of / used as substitution delimiter?
It does work surprisingly...

Edit: man sed says:

cregexpc Match lines matching the regular expression regexp. The c may be any character.

so I would have expected a leading backslash...n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, any character can be used as long (as it doesn't appear in regexp, of course) -- I picked # since that was already used in qt/configure for the same purpose.

@@ -324,7 +328,7 @@ done

# check python version
PYTHON_VERSION_REQUIRED="3.8"
PYTHON_VERSION_CURRENT=$(python${PYVERSION} --version | tr --delete 'Python ')
PYTHON_VERSION_CURRENT=$(${PYTHON} --version | tr --delete 'Python ')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful code now, well done 😃

@tguruswamy
Copy link
Contributor Author

tguruswamy commented Jan 9, 2024

Edit: OK, it is because sed does not find ^python3 anymore to replace it (once it has been changed). This is IMHO a source of problems that are hard to find. Perhaps there is a better solution that allows changing Python with every ./configure call. @ALL Any proposals?

Yes, that's right. The proper way to do this (c.f. autotools) would be to have a template file ("backintime.in") which is used to create the real "backintime" every time configure is run. This would be a more invasive change, and may not be worth it to implement right now if you are rewriting the build system anyway.

@aryoda
Copy link
Contributor

aryoda commented Jan 10, 2024

Yes, that's right. The proper way to do this (c.f. autotools) would be to have a template file ("backintime.in") which is used to create the real "backintime" every time configure is run. This would be a more invasive change, and may not be worth it to implement right now if you are rewriting the build system anyway.

I fully agree and given the fact that the python version is not changed on the build computer anymore (normally) it is IMHO a valid approach.

It would be great if you place just a short comment in the code as hint about this restriction. THX :-)

@tguruswamy
Copy link
Contributor Author

Here's a compromise to avoid rewriting too much -- a version which prints a warning if the sed python path replacement fails. Feel free to change the text to something you like better.

I removed the ssh-agent pattern because I could not find anywhere in the code where it might apply.

@buhtz
Copy link
Member

buhtz commented Jan 10, 2024

Dear @Fantu ,
as Debian co-maintainer can you please have a short look on this PR and tell is if it would negative influence the packaging process on your site?
Thanks in advance
Christian

@aryoda
Copy link
Contributor

aryoda commented Jan 10, 2024

Here's a compromise to avoid rewriting too much -- a version which prints a warning if the sed python path replacement fails. Feel free to change the text to something you like better.

Perfect as is now!

I removed the ssh-agent pattern because I could not find anywhere in the code where it might apply.

Just checked it, you are right, ssh-agent is only called from within our Python source code so no Python version must be specified:

def startSshAgent(self):
"""
Start a new ``ssh-agent`` if it is not already running.
Raises:
exceptions.MountException: if starting ``ssh-agent`` failed
"""
SOCK = 'SSH_AUTH_SOCK'
PID = 'SSH_AGENT_PID'
if os.getenv(SOCK, '') and os.getenv(PID, ''):
logger.debug(
'ssh-agent already running. Skip starting a new one.', self)
return
sshAgent = tools.which('ssh-agent')
if not sshAgent:
raise MountException(
_('ssh-agent not found. Please make sure it is installed.'))
if isinstance(sshAgent, str):
sshAgent = [sshAgent, ]
sa = subprocess.Popen(sshAgent,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
out, err = sa.communicate()
if sa.returncode:
raise MountException(
'Failed to start ssh-agent: [{}] {}'
.format(sa.returncode, err))
m = re.match(r'.*{}(?:=|\s)([^;]+);.*{}(?:=|\s)(\d+);'
.format(SOCK, PID),
out,
re.DOTALL | re.MULTILINE)
if m:
logger.debug('ssh-agent started successful: {}={} | {}={}'
.format(SOCK, m.group(1), PID, m.group(2)), self)
os.environ[SOCK] = m.group(1)
os.environ[PID] = m.group(2)
atexit.register(os.kill, int(m.group(2)), signal.SIGKILL)
else:
raise MountException(
'No matching output from ssh-agent: {} | {}'.format(out, err))

So this is useless legacy code (git blame dates this back to 2015)

@Fantu
Copy link
Contributor

Fantu commented Jan 10, 2024

Dear @Fantu , as Debian co-maintainer can you please have a short look on this PR and tell is if it would negative influence the packaging process on your site? Thanks in advance Christian

Probably not, but I'm not sure.
You could compare the contents of the generated packages for example to see the differences, the latest version in Debian compared with the one generated by adding only this patch. Should be possible with debdiff.
I'm probably too busy in these days, if you can check it, if you have difficulty I'll try to do it when I can.

@aryoda aryoda merged commit 136f466 into bit-team:dev Jan 15, 2024
1 check failed
@aryoda
Copy link
Contributor

aryoda commented Jan 15, 2024

@tguruswamy I have merged your PR now into our dev branch.
THX a lot for your excellent work helping to improve BiT! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants